/**
 * @(#) StockMonitor.java
 */

package edu.stthomas.edu.seis770.stocksystem;

import java.util.ArrayList;
import java.util.List;

public class StockMonitor implements EventSubscriber {
	List <Stock> stocks;
    public StockMonitor(){
    	stocks = new ArrayList<Stock>();
        // Subscribe to create and update events!
        List<String> eventsList = new ArrayList<String>();
        eventsList.add(EventManager.STOCK_CREATE_EVENT);
        eventsList.add(EventManager.STOCK_UPDATE_EVENT);
        EventManager.getUniqueInstance().register(this, eventsList);
    }
    @Override
    public void update(Object subject, String event) {
    	Stock stock = (Stock) subject;
    	if (event == EventManager.STOCK_CREATE_EVENT) {
    		stocks.add(stock);
    		System.out.println("A new stock (" + stock.getStockSymbol() + ") was added to Stock Monitor.");
    	}
    	else if (event == EventManager.STOCK_UPDATE_EVENT)
    		 System.out.println("Stock status of stock " + stock.getStockSymbol() + " has been updated in Stock Monitor.");
       
    	//Redisplay updated list of stocks
    	System.out.println("\nStock Monitor - Updated List of Stocks: ");
    	for (Stock s:stocks)
    	   System.out.println(s.toString());
    }


}
